package com.ymatou.iapi.coupon.testcase;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.coupon.parameter.UserReceiveCouponBean;
import com.ymatou.iapi.coupon.parameter.UserReceiveResultInfo;
import com.ymatou.iapi.coupon.service.UserReceiveCouponCall;
import com.ymatou.iapi.couponmanage.parameter.CreateBagBean;
import com.ymatou.iapi.couponmanage.parameter.SellerCreateBatchBean;
import com.ymatou.iapi.couponmanage.parameter.CreateCouponBean;
import com.ymatou.iapi.couponmanage.service.CreateBagCall;
import com.ymatou.iapi.couponmanage.service.CreateCouponCall;
import com.ymatou.iapi.couponmanage.service.SellerCreateBatchCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.CouponServiceMCallServiceV2;
//import com.ymttest.database.model.YmtCoupon;
//import com.ymttest.database.model.YmtCouponBatch;
//import com.ymttest.database.model.YmtCouponPrivateUserBound;
//import com.ymttest.database.model.YmtCouponScenario;
//import com.ymttest.database.model.YmtCouponSetting;
//import com.ymttest.database.model.YmtCouponValue;
import com.ymttest.database.model.coupon;
import com.ymttest.database.model.couponbatch;
import com.ymttest.database.sqlwapper.YmtCouponBatchWapper;
//import com.ymttest.database.sqlwapper.YmtCouponPrivateUserBoundWapper;
//import com.ymttest.database.sqlwapper.YmtCouponScenarioWapper;
//import com.ymttest.database.sqlwapper.YmtCouponSettingWapper;
//import com.ymttest.database.sqlwapper.YmtCouponValueWapper;
import com.ymttest.database.sqlwapper.couponWapper;
import com.ymttest.database.sqlwapper.couponbatchWapper;
import com.ymttest.utils.TestDataManager;
/**
*用户领取优惠券
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_UserReceiveCoupon {
	private static UserReceiveCouponBean userreceivecouponBean;
	private static UserReceiveCouponCall userreceivecouponCall;
	private couponbatchWapper couponbatchWapper=new couponbatchWapper();

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("用户领取优惠券用例-领取商家优惠券-商品详情购买页的领取");
	}

	@Before
	public void caseUp() {
		userreceivecouponBean = new UserReceiveCouponBean();
		userreceivecouponCall = new UserReceiveCouponCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(userreceivecouponCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UserReceiveCoupon_001() {
		Logger.start(true, "用户领取优惠券-平台券");
		try {

			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();

			// 平台优惠券-链接
			CreateCouponBean createcouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();	
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createcouponBean);

			userreceivecouponBean = couponCallService.setUserReceiveCouponBean(createCouponCall.getBatchCode());
			userreceivecouponBean.setSellerShopName(null);
			userreceivecouponBean.setUserId(20324128);		
			userreceivecouponBean.setAppId("www.ymatou.com");
			userreceivecouponCall.setData(userreceivecouponBean);
			userreceivecouponCall.callService();
			VerifyReturn(createcouponBean);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UserReceiveCoupon_010() {
		Logger.start(true, "用户领取优惠券-平台券-一个用户最多可以领取多张");
		try {

			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();

			// 平台优惠券-链接
			CreateCouponBean createcouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();	
			createcouponBean.setPerUserReceiveMaxCount(2);
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createcouponBean);

			userreceivecouponBean = couponCallService.setUserReceiveCouponBean(createCouponCall.getBatchCode());
			userreceivecouponBean.setUserId(20324128);		

			userreceivecouponCall.setData(userreceivecouponBean);
			userreceivecouponCall.callService();
			VerifyReturn(createcouponBean);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UserReceiveCoupon_012() {
		Logger.start(true, "用户领取优惠券-平台券-一个用户同时领取2张");
		try {

			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();

			// 平台优惠券-链接
			CreateCouponBean createcouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();	
			createcouponBean.setPerUserReceiveMaxCount(2);
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createcouponBean);

			userreceivecouponBean = couponCallService.setUserReceiveCouponBean(createCouponCall.getBatchCode());
			userreceivecouponBean.setUserId(20324128);		

			userreceivecouponCall.setData(userreceivecouponBean);
			userreceivecouponCall.callService();
			userreceivecouponCall.callService();
			VerifyReturn(createcouponBean);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UserReceiveCoupon_002() { 
		Logger.start(true, "用户领取优惠券-商家券");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();	

			// 商家优惠券
		    SellerCreateBatchBean couponBatchBean = couponCallService.setDefaultSellerCreateBatchBean();
			String batchCode = couponCallService.SellerCreateBatch(couponBatchBean).getBatchCode();

			userreceivecouponBean = couponCallService.setUserReceiveCouponBean(batchCode);

			userreceivecouponCall.setData(userreceivecouponBean);
			userreceivecouponCall.callService();

			Logger.verifyEquals("0", userreceivecouponCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", userreceivecouponCall.getMessage(), "验证返回Message");

			UserReceiveResultInfo userReceiveResult = userreceivecouponCall.getUserReceiveResult();

			// 验证返回
			Logger.verifyEquals(userreceivecouponBean.getUserId(), userReceiveResult.getUserId(), "验证返回UserId");
			Logger.verifyEquals(userreceivecouponBean.getBatchCode(), userReceiveResult.getBatchCode(), "验证返回BatchCode");
			Logger.verifyEquals(true, userReceiveResult.getIsReceiveSuccess(), "验证返回isReceiveSuccess");
			Logger.verifyEquals(0, userReceiveResult.getReceiveFailReason(), "验证返回UserId");

			couponbatch couponbatch = new couponbatchWapper()
					.selectBybatchCode(userreceivecouponBean.getBatchCode()).get(0);
			
			coupon coupon = new couponWapper().selectByBatchId(couponbatch.getBatchId()).get(0);
			

			Logger.verifyEquals(coupon.getCouponCode(), userReceiveResult.getCouponCode(),
					"验证返回CouponCode");
			// 验证数据库
			Logger.verifyEquals(userreceivecouponBean.getUserId(), coupon.getUserId(),
					"验证数据库表coupon中UserId");
			Logger.verifyEquals(userreceivecouponBean.getBatchCode(), couponbatch.getBatchCode(),
					"验证数据库表couponbatch中BatchCode");
			Logger.verifyEquals(coupon.getBatchId(), couponbatch.getBatchId(),
					"验证数据库表couponbatch与表coupon中batchId");

			Logger.verifyEquals(1, couponbatch.getReceivedCount(), "验证数据库表couponbatch中iReceiveCount");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UserReceiveCoupon_011() {
		Logger.start(true, "用户领取优惠券-商家券-一个用户可以领取多张");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();	

			// 商家优惠券
		    SellerCreateBatchBean couponBatchBean = couponCallService.setDefaultSellerCreateBatchBean();
		    couponBatchBean.setReceiveNumPerUser(2);
			String batchCode = couponCallService.SellerCreateBatch(couponBatchBean).getBatchCode();

			userreceivecouponBean = couponCallService.setUserReceiveCouponBean(batchCode);

			userreceivecouponCall.setData(userreceivecouponBean);
			userreceivecouponCall.callService();

			Logger.verifyEquals("0", userreceivecouponCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", userreceivecouponCall.getMessage(), "验证返回Message");

			UserReceiveResultInfo userReceiveResult = userreceivecouponCall.getUserReceiveResult();

			// 验证返回
			Logger.verifyEquals(userreceivecouponBean.getUserId(), userReceiveResult.getUserId(), "验证返回UserId");
			Logger.verifyEquals(userreceivecouponBean.getBatchCode(), userReceiveResult.getBatchCode(), "验证返回BatchCode");
			Logger.verifyEquals(true, userReceiveResult.getIsReceiveSuccess(), "验证返回isReceiveSuccess");
			Logger.verifyEquals(0, userReceiveResult.getReceiveFailReason(), "验证返回UserId");
			
			couponbatch couponbatch = new couponbatchWapper()
					.selectBybatchCode(userreceivecouponBean.getBatchCode()).get(0);
			coupon coupon = new couponWapper().selectByBatchId(couponbatch.getBatchId()).get(0);
			
			Logger.verifyEquals(coupon.getCouponCode(), userReceiveResult.getCouponCode(),
					"验证返回CouponCode");
			// 验证数据库
			Logger.verifyEquals(userreceivecouponBean.getUserId(), coupon.getUserId(),
					"验证数据库表coupon中UserId");
			Logger.verifyEquals(userreceivecouponBean.getBatchCode(), couponbatch.getBatchCode(),
					"验证数据库表couponbatch中BatchCode");
			Logger.verifyEquals(coupon.getBatchId(), couponbatch.getBatchId(),
					"验证数据库表couponbatch与表coupon中batchId");
			Logger.verifyEquals(couponbatch.getReceiveTimesPerUser()-1,userReceiveResult.getRemainReceiveTimes(), "验证返回RemainReceiveTimes");

			Logger.verifyEquals(1, couponbatch.getReceivedCount(), "验证数据库表couponbatch中iReceiveCount");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}


	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UserReceiveCoupon_004() {
		Logger.start(false, "用户领取优惠券-不在领取时间范围");
		try {

			CouponServiceMCallServiceV2 couponManageCallService = new CouponServiceMCallServiceV2();

			CreateCouponBean createcouponBean = couponManageCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			
			CreateCouponCall createCouponCall = couponManageCallService.createPlatformCoupon(createcouponBean);

			userreceivecouponBean = couponManageCallService.setUserReceiveCouponBean(createCouponCall.getBatchCode());
			userreceivecouponBean.setUserId(20324128);
			
			Date dNow = new Date(); // 当前时间
	        Date dBefore = new Date();
	        Date dAfter = new Date();

	        Calendar calendar1 = Calendar.getInstance(); // 得到日历
	        calendar1.setTime(dNow);// 把当前时间赋给日历
	        calendar1.add(Calendar.DAY_OF_MONTH, -10); // 设置为前10天
	        dBefore = calendar1.getTime(); // 得到前10天的时间

	        Calendar calendar2 = Calendar.getInstance(); // 得到日历
	        calendar2.setTime(dNow);// 把当前时间赋给日历
	        calendar2.add(Calendar.DAY_OF_MONTH, -1); // 设置为前1天
	        dAfter = calendar2.getTime(); // 得到前一天的时间

	   
	    	new couponbatchWapper().setAcquireStartTime(createCouponCall.getBatchCode(), dBefore);
	    	new couponbatchWapper().setAcquireEndTime(createCouponCall.getBatchCode(), dAfter);
		
			userreceivecouponCall.setData(userreceivecouponBean);
			userreceivecouponCall.callService();

			Logger.verifyEquals("0", userreceivecouponCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", userreceivecouponCall.getMessage(), "验证返回Message");

			UserReceiveResultInfo userReceiveResult = userreceivecouponCall.getUserReceiveResult();

			// 验证返回
			Logger.verifyEquals(userreceivecouponBean.getUserId(), userReceiveResult.getUserId(), "验证返回UserId");
			Logger.verifyEquals(userreceivecouponBean.getBatchCode(), userReceiveResult.getBatchCode(),
					"验证返回BatchCode");
			Logger.verifyEquals(false, userReceiveResult.getIsReceiveSuccess(), "验证返回IsReceiveSuccess(");
			Logger.verifyEquals(14, userReceiveResult.getReceiveFailReason(), "验证返回ReceiveFailReason");
			Logger.verifyEquals("超出领取结束时间", userReceiveResult.getRemark(), "验证返回ReceiveFailReason");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UserReceiveCoupon_005() {
		Logger.start(false, "用户领取优惠券-平台链接-批次不能用于领取");
		try {

			CouponServiceMCallServiceV2 couponManageCallService = new CouponServiceMCallServiceV2();

			CreateCouponBean createcouponBean = couponManageCallService.setDefaultPlatformCreateCouponBeanForConversion();
			CreateCouponCall createCouponCall = couponManageCallService.createPlatformCoupon(createcouponBean);

			userreceivecouponBean = couponManageCallService.setUserReceiveCouponBean(createCouponCall.getBatchCode());
			userreceivecouponBean.setUserId(20324128);

			userreceivecouponCall.setData(userreceivecouponBean);
			userreceivecouponCall.callService();

			Logger.verifyEquals("2", userreceivecouponCall.getCode(), "验证返回code");
			Logger.verifyEquals(true, IsContain(userreceivecouponCall.getMessage(),"批次仅允许兑换，不允许直接领取"), "验证返回Message");

			//UserReceiveResultInfo userReceiveResult = userreceivecouponCall.getUserReceiveResult();

			// 验证返回
//			Logger.verifyEquals(userreceivecouponBean.getUserId(), userReceiveResult.getUserId(), "验证返回UserId");
//			Logger.verifyEquals(userreceivecouponBean.getBatchCode(), userReceiveResult.getBatchCode(),
//					"验证返回BatchCode");
//			Logger.verifyEquals(false, userReceiveResult.getIsReceiveSuccess(), "验证返回IsReceiveSuccess");
//			Logger.verifyEquals(19, userReceiveResult.getReceiveFailReason(), "验证返回ReceiveFailReason");
//			Logger.verifyEquals("批次不能用于领取", userReceiveResult.getRemark(), "验证返回ReceiveFailReason");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UserReceiveCoupon_006() {
		Logger.start(false, "用户领取优惠券-平台链接-批次不存在");
		try {

			CouponServiceMCallServiceV2 couponManageCallService = new CouponServiceMCallServiceV2();

			userreceivecouponBean = couponManageCallService.setUserReceiveCouponBean("99999999");
			userreceivecouponBean.setUserId(20324128);

			userreceivecouponCall.setData(userreceivecouponBean);
			userreceivecouponCall.callService();

			Logger.verifyEquals("2", userreceivecouponCall.getCode(), "验证返回code");
			Logger.verifyEquals(true, IsContain(userreceivecouponCall.getMessage(),"批次不存在"), "验证返回Message");

		//	UserReceiveResultInfo userReceiveResult = userreceivecouponCall.getUserReceiveResult();

			// 验证返回
//			Logger.verifyEquals(userreceivecouponBean.getUserId(), userReceiveResult.getUserId(), "验证返回UserId");
//			Logger.verifyEquals(userreceivecouponBean.getBatchCode(), userReceiveResult.getBatchCode(), "验证返回BatchCode");
//			Logger.verifyEquals(false, userReceiveResult.getIsReceiveSuccess(), "验证返回IsReceiveSuccess(");
//			Logger.verifyEquals(8, userReceiveResult.getReceiveFailReason(), "验证返回ReceiveFailReason");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UserReceiveCoupon_007() {
		Logger.start(true, "用户领取优惠券-平台链接-coupon相对立即生效的优惠券截止时间至23:59:59S-JIRACONN-13324");
		try {

			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();

			// 平台优惠券-链接
			CreateCouponBean createcouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();	
			
			createcouponBean.setEffectiveType(1);
			createcouponBean.setEffectiveValidType(0);
			createcouponBean.setEffectiveDays(1);
			
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createcouponBean);
			Thread.sleep(1000);

			userreceivecouponBean = couponCallService.setUserReceiveCouponBean(createCouponCall.getBatchCode());	

			userreceivecouponCall.setData(userreceivecouponBean);
			userreceivecouponCall.callService();

			VerifyReturn(createcouponBean);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UserReceiveCoupon_008() {
		Logger.start(false, "用户领取优惠券-商家券- JIRACONN-15533 : 可以领取买手还未生效的优惠券 ");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();	

			// 商家优惠券
			SellerCreateBatchBean couponBatchBean = couponCallService.setDefaultSellerCreateBatchBean();
			
			Date dNow = new Date(); // 当前时间
			Date dBefore = new Date();

			Calendar calendar1 = Calendar.getInstance(); // 得到日历
			calendar1.setTime(dNow);// 把当前时间赋给日历
			calendar1.add(Calendar.DAY_OF_MONTH, 1); // 设置为前一天
			dBefore = calendar1.getTime(); // 得到前一天的时间

			couponBatchBean.setEffectiveStartDate(dBefore);
			String batchCode = couponCallService.SellerCreateBatch(couponBatchBean).getBatchCode();

			userreceivecouponBean = couponCallService.setUserReceiveCouponBean(batchCode);

			userreceivecouponCall.setData(userreceivecouponBean);
			userreceivecouponCall.callService();

			Logger.verifyEquals("0", userreceivecouponCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", userreceivecouponCall.getMessage(), "验证返回Message");

			UserReceiveResultInfo userReceiveResult = userreceivecouponCall.getUserReceiveResult();

			// 验证返回
			Logger.verifyEquals("0", new JSONObject(userreceivecouponCall.getData()).getString("errorCode"), "验证返回errorCode");

			Logger.verifyEquals("操作成功！", userreceivecouponCall.getMessage(), "验证返回Message");
			
			Logger.verifyEquals(true, userReceiveResult.getRemark().contains("未到领取开始时间"), "验证返回UserReceiveResultList");
			Logger.verifyEquals(13, userReceiveResult.getReceiveFailReason(), "验证返回ReceiveFailReason");
			Logger.verifyEquals(false, userReceiveResult.getIsReceiveSuccess(), "验证返回IsReceiveSuccess");
		

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UserReceiveCoupon_009() {
		Logger.start(false, "用户领取优惠券-不在领取时间范围");
		try {

			CouponServiceMCallServiceV2 couponManageCallService = new CouponServiceMCallServiceV2();

			CreateCouponBean createcouponBean = couponManageCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			
			Date dNow = new Date(); // 当前时间
			Date dBefore = new Date();

			Calendar calendar1 = Calendar.getInstance(); // 得到日历
			calendar1.setTime(dNow);// 把当前时间赋给日历
			calendar1.add(Calendar.DAY_OF_MONTH, 1); // 设置为前一天
			dBefore = calendar1.getTime(); // 得到前一天的时间

			createcouponBean.setAcquireStartTime(dBefore);
			
			CreateCouponCall createCouponCall = couponManageCallService.createPlatformCoupon(createcouponBean);

			userreceivecouponBean = couponManageCallService.setUserReceiveCouponBean(createCouponCall.getBatchCode());
			userreceivecouponBean.setUserId(20324128);
			
			userreceivecouponCall.setData(userreceivecouponBean);
			userreceivecouponCall.callService();

			Logger.verifyEquals("0", userreceivecouponCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", userreceivecouponCall.getMessage(), "验证返回Message");

			UserReceiveResultInfo userReceiveResult = userreceivecouponCall.getUserReceiveResult();

			// 验证返回
			Logger.verifyEquals(userreceivecouponBean.getUserId(), userReceiveResult.getUserId(), "验证返回UserId");
			Logger.verifyEquals(userreceivecouponBean.getBatchCode(), userReceiveResult.getBatchCode(),
					"验证返回BatchCode");
			Logger.verifyEquals(false, userReceiveResult.getIsReceiveSuccess(), "验证返回IsReceiveSuccess(");
			Logger.verifyEquals(13, userReceiveResult.getReceiveFailReason(), "验证返回ReceiveFailReason");
			Logger.verifyEquals("未到领取开始时间", userReceiveResult.getRemark(), "验证返回ReceiveFailReason");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UserReceiveCoupon_013() {
		Logger.start(true, "用户领取优惠券-套券");
		try {
			CouponServiceMCallServiceV2 CouponServiceMCallServiceV2 = new CouponServiceMCallServiceV2();
			CreateBagBean createBagBean = CouponServiceMCallServiceV2.setDefaultPlatformCreateCouponBagBeanForRecieve();
			CreateBagCall createBagCall = CouponServiceMCallServiceV2.createPlatformCouponBag(createBagBean);
			List<String> batchCodes = new ArrayList<>();
			batchCodes.add(createBagCall.getbagCode());		

			userreceivecouponBean = CouponServiceMCallServiceV2.setUserReceiveCouponBean(createBagCall.getbagCode());
			userreceivecouponBean.setUserId(20324128);	
			
			userreceivecouponCall.setData(userreceivecouponBean);
			userreceivecouponCall.callService();
			//VerifyReturn(createcouponBean);
			//平台券异步JOB回调更新批次已领取和使用数量，放到Job,目前为了测试方便，直接调用
			new CouponServiceMCallServiceV2().updatereceivedandusedcount();
			Logger.verifyEquals("0", userreceivecouponCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", userreceivecouponCall.getMessage(), "验证返回Message");

			UserReceiveResultInfo userReceiveResult = userreceivecouponCall.getUserReceiveResult();
			couponbatch couponbatch = new couponbatchWapper().getCouponBatchByBagCode(userreceivecouponBean.getBatchCode())
					.get(0);
			coupon coupon = new couponWapper().selectByBatchId(couponbatch.getBatchId()).get(0);
			// 验证返回
			Logger.verifyEquals(0, new JSONObject(userreceivecouponCall.getData()).getInt("errorCode"), "验证返回errorCode");
			Logger.verifyEquals("null", new JSONObject(userreceivecouponCall.getData()).getString("errorMessage"), "验证返回errorMessage");
			
			Logger.verifyEquals(userreceivecouponBean.getUserId(), userReceiveResult.getUserId(), "验证返回UserId");
			Logger.verifyEquals(userreceivecouponBean.getBatchCode(), userReceiveResult.getBatchCode(), "验证返回BatchCode");
			Logger.verifyEquals(0, userReceiveResult.getReceiveFailReason(), "验证返回ReceiveFailReason");
			Logger.verifyEquals("成功", userReceiveResult.getRemark(), "验证返回Remark");
			
			Logger.verifyEquals(couponbatch.getReceiveTimesPerUser()-couponbatch.getReceivedCount(),userReceiveResult.getRemainReceiveTimes(), "验证返回RemainReceiveTimes");
			Logger.verifyEquals(coupon.getCouponCode(), userReceiveResult.getCouponCode(), "验证返回CouponCode");
			
			Logger.verifyEquals(true, userReceiveResult.getIsReceiveSuccess(), "验证返回IsReceiveSuccess");
			
			
			// 验证数据库
			Logger.verifyEquals(coupon.getCouponCode(), userReceiveResult.getCouponCode(),
					"验证返回CouponCode");
			Logger.verifyEquals(userreceivecouponBean.getUserId(), coupon.getUserId(),
					"验证数据库表coupon中UserId");
			Logger.verifyEquals(userreceivecouponBean.getBatchCode(), couponbatch.getBagCode(),
					"验证数据库表couponbatch中BagCode");
			Logger.verifyEquals(coupon.getBatchId(), couponbatch.getBatchId(),
					"验证数据库表couponbatch与表coupon中batchId");
			
			Logger.verifyEquals(userreceivecouponBean.getUserId(), coupon.getUserId(),
					"验证数据库表coupon中UserId");
			Logger.verifyEquals(userReceiveResult.getCouponCode(), coupon.getCouponCode(),
					"验证数据库表coupon中couponCode");
			Logger.verifyEquals(false, coupon.getIsUsed(),
					"验证数据库表coupon中IsUsed");
			// coupon相对立即生效的优惠券截止时间至23:59:59S-JIRACONN-13324
			if(createBagBean.getEffectiveType()==1&&createBagBean.getEffectiveValidType()==0)
			{
				Date validStart = coupon.getValidStart();
				Calendar calendar1 = Calendar.getInstance(); // 得到日历
				calendar1.setTime(validStart);// 把当前时间赋给日历
				calendar1.add(Calendar.DAY_OF_MONTH, createBagBean.getEffectiveDays()); // 设置为前一天
				Date validEnd = calendar1.getTime(); // 得到前一天的时间
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
				Logger.verifyEquals(sdf.format(validEnd).substring(0, 10)+" 23:59:59.000", sdf.format(coupon.getValidEnd()), "验证Coupon表ValidEnd");
			}
			
			Logger.verifyEquals(userreceivecouponBean.getBusinessType(), coupon.getCreaterType(),
					"验证数据库表coupon中createrType");
			Logger.verifyEquals(0, coupon.getSellerId(),
					"验证数据库表coupon中sellerId");
			Logger.verifyEquals(couponbatch.getBatchId().toString(), coupon.getBatchId().toString(),
					"验证数据库表coupon中batchId");
			Logger.verifyEquals("0", coupon.getMainOrderId().toString(),
					"验证数据库表coupon中mainOrderId");
			Logger.verifyEquals(false, coupon.getIsInvalid().booleanValue(),
					"验证数据库表coupon中isInvalid");
			Logger.verifyEquals(userReceiveResult.getBatchCode(), coupon.getBagCode(),
					"验证数据库表coupon中bagCode");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UserReceiveCoupon_014() {
		Logger.start(true, "用户领取优惠券-活动优惠券-JIRACONN-23166");
		try {

			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();

			// 平台优惠券-链接
			SellerCreateBatchBean createcouponBean = couponCallService.setDefaultSellerCreateBatch_ActivityBean();	
			SellerCreateBatchCall createCouponCall = couponCallService.SellerCreateBatch(createcouponBean);

			userreceivecouponBean = couponCallService.setUserReceiveCouponBean(createCouponCall.getBatchCode());
			userreceivecouponBean.setUserId(20324128);		

			userreceivecouponCall.setData(userreceivecouponBean);
			userreceivecouponCall.callService();
			Logger.verifyEquals("0", userreceivecouponCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", userreceivecouponCall.getMessage(), "验证返回Message");

			UserReceiveResultInfo userReceiveResult = userreceivecouponCall.getUserReceiveResult();

			// 验证返回
			Logger.verifyEquals(userreceivecouponBean.getUserId(), userReceiveResult.getUserId(), "验证返回UserId");
			Logger.verifyEquals(userreceivecouponBean.getBatchCode(), userReceiveResult.getBatchCode(), "验证返回BatchCode");
			Logger.verifyEquals(true, userReceiveResult.getIsReceiveSuccess(), "验证返回isReceiveSuccess");
			Logger.verifyEquals(0, userReceiveResult.getReceiveFailReason(), "验证返回UserId");

			couponbatch couponbatch = new couponbatchWapper()
					.selectBybatchCode(userreceivecouponBean.getBatchCode()).get(0);
			
			coupon coupon = new couponWapper().selectByBatchId(couponbatch.getBatchId()).get(0);
			

			Logger.verifyEquals(coupon.getCouponCode(), userReceiveResult.getCouponCode(),
					"验证返回CouponCode");
			// 验证数据库
			Logger.verifyEquals(userreceivecouponBean.getUserId(), coupon.getUserId(),
					"验证数据库表coupon中UserId");
			Logger.verifyEquals(userreceivecouponBean.getBatchCode(), couponbatch.getBatchCode(),
					"验证数据库表couponbatch中BatchCode");
			Logger.verifyEquals(coupon.getBatchId(), couponbatch.getBatchId(),
					"验证数据库表couponbatch与表coupon中batchId");

			Logger.verifyEquals(1, couponbatch.getReceivedCount(), "验证数据库表couponbatch中iReceiveCount");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UserReceiveCoupon_015() {
		Logger.start(true, "用户领取优惠券-活动优惠券-now<acquirestarttime && now<acquireendtime,返回为空,JIRACONN-23166");
		try {

			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();

			// 平台优惠券-链接
			SellerCreateBatchBean createcouponBean = couponCallService.setDefaultSellerCreateBatch_ActivityBean();	
			SellerCreateBatchCall createCouponCall = couponCallService.SellerCreateBatch(createcouponBean);
			Date dNow = new Date(); // 当前时间
	        Date dBefore = new Date();
	        Date dAfter = new Date();

	        Calendar calendar1 = Calendar.getInstance(); // 得到日历
	        calendar1.setTime(dNow);// 把当前时间赋给日历
	        calendar1.add(Calendar.DAY_OF_MONTH, -10); // 设置为前一天
	        dBefore = calendar1.getTime(); // 得到前一天的时间

	        Calendar calendar2 = Calendar.getInstance(); // 得到日历
	        calendar2.setTime(dNow);// 把当前时间赋给日历
	        calendar2.add(Calendar.DAY_OF_MONTH, -1); // 设置为后十天
	        dAfter = calendar2.getTime(); // 得到前一天的时间
			new couponbatchWapper().setAcquireStartTime(createCouponCall.getBatchCode(), dBefore);
			new couponbatchWapper().setAcquireEndTime(createCouponCall.getBatchCode(), dAfter);
			
			userreceivecouponBean = couponCallService.setUserReceiveCouponBean(createCouponCall.getBatchCode());
			userreceivecouponBean.setUserId(20324128);		

			userreceivecouponCall.setData(userreceivecouponBean);
			userreceivecouponCall.callService();
			Logger.verifyEquals("0", userreceivecouponCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", userreceivecouponCall.getMessage(), "验证返回Message");

			UserReceiveResultInfo userReceiveResult = userreceivecouponCall.getUserReceiveResult();

			// 验证返回
			Logger.verifyEquals(userreceivecouponBean.getUserId(), userReceiveResult.getUserId(), "验证返回UserId");
			Logger.verifyEquals(userreceivecouponBean.getBatchCode(), userReceiveResult.getBatchCode(), "验证返回BatchCode");
			Logger.verifyEquals(false, userReceiveResult.getIsReceiveSuccess(), "验证返回isReceiveSuccess");
			Logger.verifyEquals(14, userReceiveResult.getReceiveFailReason(), "验证返回UserId");
			Logger.verifyEquals(true, userReceiveResult.getRemark().contains("超出领取结束时间"), "验证返回remark");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UserReceiveCoupon_016() {
		Logger.start(true, "用户领取优惠券-平台券,now<acquirestarttime && now<acquireendtime,返回为空,JIRACONN-23166");
		try {

			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			// 平台优惠券-链接
			CreateCouponBean createcouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();	
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createcouponBean);

			Date dNow = new Date(); // 当前时间
	        Date dBefore = new Date();
	        Date dAfter = new Date();

	        Calendar calendar1 = Calendar.getInstance(); // 得到日历
	        calendar1.setTime(dNow);// 把当前时间赋给日历
	        calendar1.add(Calendar.DAY_OF_MONTH, -10); // 设置为前一天
	        dBefore = calendar1.getTime(); // 得到前一天的时间

	        Calendar calendar2 = Calendar.getInstance(); // 得到日历
	        calendar2.setTime(dNow);// 把当前时间赋给日历
	        calendar2.add(Calendar.DAY_OF_MONTH, -1); // 设置为后十天
	        dAfter = calendar2.getTime(); // 得到前一天的时间
			new couponbatchWapper().setAcquireStartTime(createCouponCall.getBatchCode(), dBefore);
			new couponbatchWapper().setAcquireEndTime(createCouponCall.getBatchCode(), dAfter);
			
			userreceivecouponBean = couponCallService.setUserReceiveCouponBean(createCouponCall.getBatchCode());
			userreceivecouponBean.setUserId(20324128);		

			userreceivecouponCall.setData(userreceivecouponBean);
			userreceivecouponCall.callService();

			UserReceiveResultInfo userReceiveResult = userreceivecouponCall.getUserReceiveResult();
			// 验证返回
			Logger.verifyEquals(userreceivecouponBean.getUserId(), userReceiveResult.getUserId(), "验证返回UserId");
			Logger.verifyEquals(userreceivecouponBean.getBatchCode(), userReceiveResult.getBatchCode(), "验证返回BatchCode");
			Logger.verifyEquals(false, userReceiveResult.getIsReceiveSuccess(), "验证返回isReceiveSuccess");
			Logger.verifyEquals(14, userReceiveResult.getReceiveFailReason(), "验证返回UserId");
			Logger.verifyEquals(true, userReceiveResult.getRemark().contains("超出领取结束时间"), "验证返回remark");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UserReceiveCoupon_017() {
		Logger.start(true, "用户领取优惠券-商家券,now<acquirestarttime && now<acquireendtime,返回为空,JIRACONN-23166");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();	

			// 商家优惠券
		    SellerCreateBatchBean couponBatchBean = couponCallService.setDefaultSellerCreateBatchBean();
			String batchCode = couponCallService.SellerCreateBatch(couponBatchBean).getBatchCode();

			Date dNow = new Date(); // 当前时间
	        Date dBefore = new Date();
	        Date dAfter = new Date();

	        Calendar calendar1 = Calendar.getInstance(); // 得到日历
	        calendar1.setTime(dNow);// 把当前时间赋给日历
	        calendar1.add(Calendar.DAY_OF_MONTH, -10); // 设置为前一天
	        dBefore = calendar1.getTime(); // 得到前一天的时间

	        Calendar calendar2 = Calendar.getInstance(); // 得到日历
	        calendar2.setTime(dNow);// 把当前时间赋给日历
	        calendar2.add(Calendar.DAY_OF_MONTH, -1); // 设置为后十天
	        dAfter = calendar2.getTime(); // 得到前一天的时间
			new couponbatchWapper().setAcquireStartTime(batchCode, dBefore);
			new couponbatchWapper().setAcquireEndTime(batchCode, dAfter);
			
			userreceivecouponBean = couponCallService.setUserReceiveCouponBean(batchCode);

			userreceivecouponCall.setData(userreceivecouponBean);
			userreceivecouponCall.callService();

			Logger.verifyEquals("0", userreceivecouponCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", userreceivecouponCall.getMessage(), "验证返回Message");

			UserReceiveResultInfo userReceiveResult = userreceivecouponCall.getUserReceiveResult();

			// 验证返回
			Logger.verifyEquals(userreceivecouponBean.getUserId(), userReceiveResult.getUserId(), "验证返回UserId");
			Logger.verifyEquals(userreceivecouponBean.getBatchCode(), userReceiveResult.getBatchCode(), "验证返回BatchCode");
			Logger.verifyEquals(false, userReceiveResult.getIsReceiveSuccess(), "验证返回isReceiveSuccess");
			Logger.verifyEquals(14, userReceiveResult.getReceiveFailReason(), "验证返回UserId");
			Logger.verifyEquals(true, userReceiveResult.getRemark().contains("超出领取结束时间"), "验证返回remark");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UserReceiveCoupon_018() { 
		Logger.start(true, "用户领取优惠券-商家券-分销");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();	

			// 商家优惠券
		    SellerCreateBatchBean couponBatchBean = couponCallService.setDefaultSellerCreateBatchBean();
			String batchCode = couponCallService.SellerCreateBatch(couponBatchBean).getBatchCode();
			couponbatchWapper.setPlatformSource(1, batchCode);
			
			userreceivecouponBean = couponCallService.setUserReceiveCouponBean(batchCode);

			userreceivecouponCall.setData(userreceivecouponBean);
			userreceivecouponCall.callService();

			Logger.verifyEquals("0", userreceivecouponCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", userreceivecouponCall.getMessage(), "验证返回Message");

			UserReceiveResultInfo userReceiveResult = userreceivecouponCall.getUserReceiveResult();

			// 验证返回
			Logger.verifyEquals(userreceivecouponBean.getUserId(), userReceiveResult.getUserId(), "验证返回UserId");
			Logger.verifyEquals(userreceivecouponBean.getBatchCode(), userReceiveResult.getBatchCode(), "验证返回BatchCode");
			Logger.verifyEquals(true, userReceiveResult.getIsReceiveSuccess(), "验证返回isReceiveSuccess");
			Logger.verifyEquals(0, userReceiveResult.getReceiveFailReason(), "验证返回UserId");

			couponbatch couponbatch = new couponbatchWapper()
					.selectBybatchCode(userreceivecouponBean.getBatchCode()).get(0);
			
			coupon coupon = new couponWapper().selectByBatchId(couponbatch.getBatchId()).get(0);
			

			Logger.verifyEquals(coupon.getCouponCode(), userReceiveResult.getCouponCode(),
					"验证返回CouponCode");
			// 验证数据库
			Logger.verifyEquals(userreceivecouponBean.getUserId(), coupon.getUserId(),
					"验证数据库表coupon中UserId");
			Logger.verifyEquals(userreceivecouponBean.getBatchCode(), couponbatch.getBatchCode(),
					"验证数据库表couponbatch中BatchCode");
			Logger.verifyEquals(coupon.getBatchId(), couponbatch.getBatchId(),
					"验证数据库表couponbatch与表coupon中batchId");

			Logger.verifyEquals(1, couponbatch.getReceivedCount(), "验证数据库表couponbatch中iReceiveCount");
			//分销字段
			Logger.verifyEquals(coupon.getPlatformSource(), couponbatch.getPlatformSource(),
					"验证数据库表couponbatch 中的字段PlatformSource与表coupon字段PlatformSource一致");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UserReceiveCoupon_019() {
		Logger.start(true, "用户领取优惠券-商家券-一个用户可以领取多张-分销");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();	

			// 商家优惠券
		    SellerCreateBatchBean couponBatchBean = couponCallService.setDefaultSellerCreateBatchBean();
		    couponBatchBean.setReceiveNumPerUser(2);
			String batchCode = couponCallService.SellerCreateBatch(couponBatchBean).getBatchCode();
            //分销
			couponbatchWapper.setPlatformSource(1, batchCode);
			
			userreceivecouponBean = couponCallService.setUserReceiveCouponBean(batchCode);

			userreceivecouponCall.setData(userreceivecouponBean);
			userreceivecouponCall.callService();

			Logger.verifyEquals("0", userreceivecouponCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", userreceivecouponCall.getMessage(), "验证返回Message");

			UserReceiveResultInfo userReceiveResult = userreceivecouponCall.getUserReceiveResult();

			// 验证返回
			Logger.verifyEquals(userreceivecouponBean.getUserId(), userReceiveResult.getUserId(), "验证返回UserId");
			Logger.verifyEquals(userreceivecouponBean.getBatchCode(), userReceiveResult.getBatchCode(), "验证返回BatchCode");
			Logger.verifyEquals(true, userReceiveResult.getIsReceiveSuccess(), "验证返回isReceiveSuccess");
			Logger.verifyEquals(0, userReceiveResult.getReceiveFailReason(), "验证返回UserId");
			
			couponbatch couponbatch = new couponbatchWapper()
					.selectBybatchCode(userreceivecouponBean.getBatchCode()).get(0);
			coupon coupon = new couponWapper().selectByBatchId(couponbatch.getBatchId()).get(0);
			
			Logger.verifyEquals(coupon.getCouponCode(), userReceiveResult.getCouponCode(),
					"验证返回CouponCode");
			// 验证数据库
			Logger.verifyEquals(userreceivecouponBean.getUserId(), coupon.getUserId(),
					"验证数据库表coupon中UserId");
			Logger.verifyEquals(userreceivecouponBean.getBatchCode(), couponbatch.getBatchCode(),
					"验证数据库表couponbatch中BatchCode");
			Logger.verifyEquals(coupon.getBatchId(), couponbatch.getBatchId(),
					"验证数据库表couponbatch与表coupon中batchId");
			Logger.verifyEquals(couponbatch.getReceiveTimesPerUser()-1,userReceiveResult.getRemainReceiveTimes(), "验证返回RemainReceiveTimes");

			Logger.verifyEquals(1, couponbatch.getReceivedCount(), "验证数据库表couponbatch中iReceiveCount");
			//分销字段
			Logger.verifyEquals(coupon.getPlatformSource(), couponbatch.getPlatformSource(),
					"验证数据库表couponbatch 中的字段PlatformSource与表coupon字段PlatformSource一致");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UserReceiveCoupon_020() {
		Logger.start(true, "用户领取优惠券-平台券-相对时间是小时");
		try {

			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();

			// 平台优惠券-链接
			CreateCouponBean createcouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();	
			createcouponBean.setEffectiveType(1);
			createcouponBean.setEffectiveTimeType(1);
			createcouponBean.setEffectiveDays(2);
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createcouponBean);

			userreceivecouponBean = couponCallService.setUserReceiveCouponBean(createCouponCall.getBatchCode());
			userreceivecouponBean.setUserId(20324128);		

			userreceivecouponCall.setData(userreceivecouponBean);
			userreceivecouponCall.callService();
			VerifyReturn(createcouponBean);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UserReceiveCoupon_021() {
		Logger.start(true, "用户领取优惠券-商家券-仅直播是使用-相对时间是小时");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();	

			// 商家优惠券
		    SellerCreateBatchBean couponBatchBean = couponCallService.setDefaultSellerCreateBatchBean();
		    couponBatchBean.setCouponType((byte)4);
			String batchCode = couponCallService.SellerCreateBatch(couponBatchBean).getBatchCode();

			userreceivecouponBean = couponCallService.setUserReceiveCouponBean(batchCode);

			userreceivecouponCall.setData(userreceivecouponBean);
			userreceivecouponCall.callService();

			Logger.verifyEquals("0", userreceivecouponCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", userreceivecouponCall.getMessage(), "验证返回Message");

			UserReceiveResultInfo userReceiveResult = userreceivecouponCall.getUserReceiveResult();

			// 验证返回
			Logger.verifyEquals(userreceivecouponBean.getUserId(), userReceiveResult.getUserId(), "验证返回UserId");
			Logger.verifyEquals(userreceivecouponBean.getBatchCode(), userReceiveResult.getBatchCode(), "验证返回BatchCode");
			Logger.verifyEquals(true, userReceiveResult.getIsReceiveSuccess(), "验证返回isReceiveSuccess");
			Logger.verifyEquals(0, userReceiveResult.getReceiveFailReason(), "验证返回UserId");

			couponbatch couponbatch = new couponbatchWapper()
					.selectBybatchCode(userreceivecouponBean.getBatchCode()).get(0);
			coupon coupon = new couponWapper().selectByBatchId(couponbatch.getBatchId()).get(0);
			
			Logger.verifyEquals(coupon.getCouponCode(), userReceiveResult.getCouponCode(),
					"验证返回CouponCode");
			// 验证数据库
			Logger.verifyEquals(userreceivecouponBean.getUserId(), coupon.getUserId(),
					"验证数据库表coupon中UserId");
			Logger.verifyEquals(userreceivecouponBean.getBatchCode(), couponbatch.getBatchCode(),
					"验证数据库表couponbatch中BatchCode"); 
			Logger.verifyEquals(coupon.getBatchId(), couponbatch.getBatchId(),
					"验证数据库表couponbatch与表coupon中batchId");

			Logger.verifyEquals(1, couponbatch.getReceivedCount(), "验证数据库表couponbatch中iReceiveCount");
			
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
			Date validStart = coupon.getValidStart();
			Calendar calendar1 = Calendar.getInstance(); // 得到日历
			calendar1.setTime(validStart);// 把当前时间赋给日历
			calendar1.add(Calendar.HOUR_OF_DAY, 12);
		    Date validEnd = calendar1.getTime(); // 得到前一天的时间
		    
		    Logger.verifyEquals(sdf.format(validEnd), sdf.format(coupon.getValidEnd()), "验证Coupon表ValidEnd");
		   // Logger.verifyEquals(coupon.getAddTime(), coupon.getValidStart(), "验证coupon表AddTime=ValidStart");
		    
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UserReceiveCoupon_022() {
		//userbiz.iapi.ymatou.com 平台 洋码头客服优惠券、洋码头优惠券，一慢就赔
		Logger.start(true, "用户领取优惠券-平台券-屏蔽刷券");
		try {

			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();

			// 平台优惠券-链接
			CreateCouponBean createcouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();	
			createcouponBean.setCouponName("洋码头客服优惠券");
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createcouponBean);

			userreceivecouponBean = couponCallService.setUserReceiveCouponBean(createCouponCall.getBatchCode());
			userreceivecouponBean.setSellerShopName(null);
			userreceivecouponBean.setUserId(20324128);		
			userreceivecouponBean.setAppId("userbiz.iapi.ymatou.com");
			userreceivecouponCall.setData(userreceivecouponBean);
			userreceivecouponCall.callService();
			Logger.verifyEquals("2", userreceivecouponCall.getCode(), "验证返回code");
			Logger.verifyIsContains("您不能领取此类平台券", userreceivecouponCall.getMessage(), "验证返回Message");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UserReceiveCoupon_023() { 
		Logger.start(true, "用户领取优惠券-商家券-屏蔽刷券");
		try {
			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();	

			// 商家优惠券
		    SellerCreateBatchBean couponBatchBean = couponCallService.setDefaultSellerCreateBatchBean();
		    couponBatchBean.setIsShowOnPage(false);
			String batchCode = couponCallService.SellerCreateBatch(couponBatchBean).getBatchCode();

			userreceivecouponBean = couponCallService.setUserReceiveCouponBean(batchCode);
			userreceivecouponBean.setAppId("userbiz.iapi.ymatou.com");
			userreceivecouponCall.setData(userreceivecouponBean);
			userreceivecouponCall.callService();

			Logger.verifyEquals("2", userreceivecouponCall.getCode(), "验证返回code");
			Logger.verifyIsContains("您不能领取此类买手券", userreceivecouponCall.getMessage(), "验证返回Message");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UserReceiveCoupon_024() {
		//appid=seller.m.ymatou.com 的请求不能领平台券
		Logger.start(true, "用户领取优惠券-平台券-屏蔽刷券");
		try {

			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();

			// 平台优惠券-链接
			CreateCouponBean createcouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();	
			createcouponBean.setCouponName("洋码头客服优惠券");
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createcouponBean);

			userreceivecouponBean = couponCallService.setUserReceiveCouponBean(createCouponCall.getBatchCode());
			userreceivecouponBean.setSellerShopName(null);
			userreceivecouponBean.setUserId(20324128);		
			userreceivecouponBean.setAppId("seller.m.ymatou.com");
			userreceivecouponCall.setData(userreceivecouponBean);
			userreceivecouponCall.callService();
			Logger.verifyEquals("2", userreceivecouponCall.getCode(), "验证返回code");
			Logger.verifyIsContains("不能在此领取平台券", userreceivecouponCall.getMessage(), "验证返回Message");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	private void VerifyReturn(CreateCouponBean createcouponBean) throws InterruptedException, JSONException, ClientProtocolException, IOException {
		//平台券异步JOB回调更新批次已领取和使用数量，放到Job,目前为了测试方便，直接调用
		new CouponServiceMCallServiceV2().updatereceivedandusedcount();
		Logger.verifyEquals("0", userreceivecouponCall.getCode(), "验证返回code");
		Logger.verifyEquals("操作成功！", userreceivecouponCall.getMessage(), "验证返回Message");

		UserReceiveResultInfo userReceiveResult = userreceivecouponCall.getUserReceiveResult();
		couponbatch couponbatch = new couponbatchWapper().selectBybatchCode(userreceivecouponBean.getBatchCode())
				.get(0);
		coupon coupon = new couponWapper().selectByBatchId(couponbatch.getBatchId()).get(0);
		// 验证返回
		Logger.verifyEquals(0, new JSONObject(userreceivecouponCall.getData()).getInt("errorCode"), "验证返回errorCode");
		Logger.verifyEquals("null", new JSONObject(userreceivecouponCall.getData()).getString("errorMessage"), "验证返回errorMessage");
		
		Logger.verifyEquals(userreceivecouponBean.getUserId(), userReceiveResult.getUserId(), "验证返回UserId");
		Logger.verifyEquals(userreceivecouponBean.getBatchCode(), userReceiveResult.getBatchCode(), "验证返回BatchCode");
		Logger.verifyEquals(0, userReceiveResult.getReceiveFailReason(), "验证返回ReceiveFailReason");
		Logger.verifyEquals("成功", userReceiveResult.getRemark(), "验证返回Remark");
		
		Logger.verifyEquals(couponbatch.getReceiveTimesPerUser()-couponbatch.getReceivedCount(),userReceiveResult.getRemainReceiveTimes(), "验证返回RemainReceiveTimes");
		Logger.verifyEquals(coupon.getCouponCode(), userReceiveResult.getCouponCode(), "验证返回CouponCode");
		
		Logger.verifyEquals(true, userReceiveResult.getIsReceiveSuccess(), "验证返回IsReceiveSuccess");
		
		
		// 验证数据库
		Logger.verifyEquals(coupon.getCouponCode(), userReceiveResult.getCouponCode(),
				"验证返回CouponCode");
		Logger.verifyEquals(userreceivecouponBean.getUserId(), coupon.getUserId(),
				"验证数据库表coupon中UserId");
		Logger.verifyEquals(userreceivecouponBean.getBatchCode(), couponbatch.getBatchCode(),
				"验证数据库表couponbatch中BatchCode");
		Logger.verifyEquals(coupon.getBatchId(), couponbatch.getBatchId(),
				"验证数据库表couponbatch与表coupon中batchId");
		
		Logger.verifyEquals(userreceivecouponBean.getUserId(), coupon.getUserId(),
				"验证数据库表coupon中UserId");
		Logger.verifyEquals(userReceiveResult.getCouponCode(), coupon.getCouponCode(),
				"验证数据库表coupon中couponCode");
		Logger.verifyEquals(false, coupon.getIsUsed(),
				"验证数据库表coupon中IsUsed");
		// coupon相对立即生效的优惠券截止时间至23:59:59S-JIRACONN-13324
		if(createcouponBean.getEffectiveType()==1&&createcouponBean.getEffectiveValidType()==0)
		{
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
			Date validStart = coupon.getValidStart();
			Calendar calendar1 = Calendar.getInstance(); // 得到日历
			calendar1.setTime(validStart);// 把当前时间赋给日历
			if(createcouponBean.getEffectiveTimeType()==0)//天
			{
				calendar1.add(Calendar.DAY_OF_MONTH, createcouponBean.getEffectiveDays()); // 设置为前一天
				Date validEnd = calendar1.getTime(); // 得到前一天的时间
				Logger.verifyEquals(sdf.format(validEnd).substring(0, 10)+" 23:59:59.000", sdf.format(coupon.getValidEnd()), "验证Coupon表ValidEnd");
				
			}
			else if(createcouponBean.getEffectiveTimeType()==1)//小时
			{
				calendar1.add(Calendar.HOUR_OF_DAY, createcouponBean.getEffectiveDays());
				Date validEnd = calendar1.getTime(); // 得到前一天的时间
				Logger.verifyEquals(sdf.format(validEnd), sdf.format(coupon.getValidEnd()), "验证Coupon表ValidEnd");
			}
		}
		Logger.verifyEquals(userreceivecouponBean.getBusinessType(), coupon.getCreaterType(),
				"验证数据库表coupon中createrType");
		Logger.verifyEquals(0, coupon.getSellerId(),
				"验证数据库表coupon中sellerId");
		Logger.verifyEquals(couponbatch.getBatchId().toString(), coupon.getBatchId().toString(),
				"验证数据库表coupon中batchId");
		Logger.verifyEquals("0", coupon.getMainOrderId().toString(),
				"验证数据库表coupon中mainOrderId");
		Logger.verifyEquals(false, coupon.getIsInvalid().booleanValue(),
				"验证数据库表coupon中isInvalid");
		Logger.verifyEquals("", coupon.getBagCode(),
				"验证数据库表coupon中bagCode");
		
//	   Logger.verifyEquals(1, couponbatch.getReceivedCount(), "验证数据库表couponBatch中ReceivedCount");
	}  
	 private boolean IsContain(String str,String containStr)
	 {
		return str.contains(containStr);
	 }
}